<?php


	$no_of_pages = ceil($TOTAL_RECORDSET / $MAX);
	$fromRecord=$page_no+1;
	$toRecord=$page_no+$MAX;
	
 	if($no_of_pages <= 2)
	{
		if(($page_no-1) >= 1)
		{
			
			 $prevpage=$page_no - 1;
			 $PREV_PAGE_LINK.=" <a href='$my_page_name&page_no=1&next_page=1'><b>Previous</b></a> ";
		}
		
		if($TOTAL_RECORDSET > ($lastrow-1))
			 $NEXT_PAGE_LINK=" <a href='$my_page_name&page_no=2&next_page=2'><b>Next</b></a> ";
		if($page_no == 2)
			 $NEXT_PAGE_LINK="";

	}
	else
	{	
		if($no_of_pages>$page_no+5)
			$maxlimit=$page_no+5;
		else
			$maxlimit=$no_of_pages;
		
		if($page_no<5)
			$toPrint=1;
		else if ($page_no<=$no_of_pages)
			$toPrint=$page_no-4;			

		for($i=0;$toPrint<=$maxlimit;$i+=$MAX,$toPrint++)
		{	
			if ($toPrint==$page_no)
				$PAGE_NAVS.=" <a href='$my_page_name&page_no=$toPrint&next_page=$n_page' class='current'><b> ".$toPrint."</b></a> ";
			else
			{
				$n_page=$toPrint+1;
				$PAGE_NAVS.=" <a href='$my_page_name&page_no=$toPrint&next_page=$n_page' ><b>$toPrint</b></a> ";
			}
		}
		
		$CURR_PAGE =$next_page; 		
		$NAV_MSG ="Dispalying Page $CURR_PAGE of  $no_of_pages.";
		
		$lastrow1=$page_no+1;
		if($page_no<$no_of_pages)
			$NEXT_PAGE_LINK=" <a href='$my_page_name&page_no=$lastrow1&next_page=$next_page'><b>Next Page</b></a> ";	
		else
			$NEXT_PAGE_LINK="";
		
		if($page_no >1)
		{
			$prevpage=$page_no - 1;
			 $PREV_PAGE_LINK.=" <a href='$my_page_name&page_no=$prevpage'><b>Previous</b></a> ";
		}
		else
			$PREV_PAGE_LINK="";
	}
?>